<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class RoutesApi extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $roleModel = $this->table('routes_api');
        $roleModel
        ->addColumn('routes_id','integer',['signed'=>false,'comment'=> '路由ID'])
        ->addColumn('name','string',['default'=>'','limit'=>32,'comment'=> '接口名称'])
        ->addColumn('module','string',['default'=>'','limit'=>32,'comment'=> '模块名'])
        ->addColumn('controller','string',['default'=>'','limit'=>64,'comment'=> '控制器名称'])
        ->addColumn('action','string',['default'=>'','limit'=>64,'comment'=> '接口名称'])
        ->addColumn('create_time', 'datetime')
        ->addColumn('update_time', 'datetime')
        ->addColumn('status', 'integer', ['default'=>1,'comment'=>'用户状态 0无效 1有效'])
        ->create();

       $data = [
            ['name'=>'【管理端】菜单列表'      ,'module'=>'admin', 'controller'=>'auth' ,'action'=>'getRoutes'     ,'routes_id'=>'1','status'=>1],
            ['name'=>'【管理端】角色列表'      ,'module'=>'admin', 'controller'=>'auth' ,'action'=>'getRoles'      ,'routes_id'=>'1','status'=>1],
            ['name'=>'【管理端】登录'          ,'module'=>'admin', 'controller'=>'login','action'=>'login'         ,'routes_id'=>'0','status'=>1],
            ['name'=>'【管理端】短信登陆'      ,'module'=>'admin', 'controller'=>'login','action'=>'smsLogin'      ,'routes_id'=>'0','status'=>1],
            ['name'=>'【管理端】获取图形验证码','module'=>'admin', 'controller'=>'login','action'=>'getValidatCode','routes_id'=>'0','status'=>1],
            ['name'=>'【管理端】角色列表'      ,'module'=>'admin', 'controller'=>'role' ,'action'=>'list'          ,'routes_id'=>'0','status'=>1],
        ];
        $posts = $this->table('routes_api');
        $posts->insert($data)
          ->saveData();
    }
}
